#!/usr/bin/perl 
# hostlookup.pl 
use warnings;
use strict;

use Socket qw(/inet/);

die "Give me a hostname!\n" unless @ARGV;

while (my $lookup = shift @ARGV) {
   my ($name, $aliases, $type, $length, @addrs) = gethostbyname($lookup);
   if ($name) {
      foreach (@addrs) {
         $_ = inet_ntoa($_);
      }
      if ($name eq $lookup) {
         print "$lookup has IP address: @addrs\n";
      } else {
         print "$lookup (real name $name) has IP address: @addrs\n";
      }
   } else {
      print "$lookup not found\n";
   }
}
